/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.form.client.value.impl;

import java.util.HashMap;
import java.util.Map;

import com.genia.toolbox.web.gwt.form.client.value.DataIdentifier;
import com.genia.toolbox.web.gwt.form.client.value.FormComplexValue;
import com.genia.toolbox.web.gwt.form.client.value.FormSimpleValue;
import com.genia.toolbox.web.gwt.form.client.value.FormValues;

/**
 * implementation of <code>FormValues</code>.
 */
public class FormValuesImpl
    implements FormValues
{

  /**
   * the identifier of the
   * {@link com.genia.toolbox.web.gwt.form.client.form.Form} associated with
   * this values.
   */
  private String formIdentifier;

  /**
   * the identifier of the object being edited.
   */
  private DataIdentifier dataIdentifier;

  /**
   * all the simple values of the items of the form being edited, indexed by
   * their name.
   * 
   */
  private Map<String, FormSimpleValue>formSimpleValues = new HashMap<String, FormSimpleValue>();

  /**
   * all the complexe values of the items of the form being edited, indexed by
   * their name.
   * 
   */
  private Map<String, FormComplexValue>formComplexValues = new HashMap<String, FormComplexValue>();



  /**
   * constructor.
   */
  public FormValuesImpl()
  {
    // do nothing.
  }



  /**
   * getter for the dataIdentifier property.
   * 
   * @return the dataIdentifier
   */
  public DataIdentifier getDataIdentifier()
  {
    return dataIdentifier;
  }



  /**
   * setter for the dataIdentifier property.
   * 
   * @param dataIdentifier
   *          the dataIdentifier to set
   */
  public void setDataIdentifier(DataIdentifier dataIdentifier)
  {
    this.dataIdentifier = dataIdentifier;
  }



  /**
   * getter for the formIdentifier property.
   * 
   * @return the formIdentifier
   */
  public String getFormIdentifier()
  {
    return formIdentifier;
  }



  /**
   * setter for the formIdentifier property.
   * 
   * @param formIdentifier
   *          the formIdentifier to set
   */
  public void setFormIdentifier(String formIdentifier)
  {
    this.formIdentifier = formIdentifier;
  }



  /**
   * convenient methis that adds a new {@link FormSimpleValue} It is equivalent
   * to
   * <code>getFormValues.put(formSimpleValue.getName(), formSimpleValue)</code>.
   * 
   * @param formSimpleValue
   *          the form value to add
   */
  public void addFormSimpleValue(final FormSimpleValue formSimpleValue)
  {
    formSimpleValues.put(formSimpleValue.getName(), formSimpleValue);
  }



  /**
   * convenient methis that returns the value of the form item with the name
   * given in parameters. It is equivalent to
   * <code>getFormValues.get(name)</code>.
   * 
   * @param name
   *          the name of the form item
   * @return the value of the item with the name given in parameter
   */
  public FormSimpleValue getFormSimpleValue(final String name)
  {
    return formSimpleValues.get(name);
  }



  /**
   * convenient method that returns the value of the form item with the name
   * given in parameters. It is equivalent to
   * <code>getFormComplexValues().get(name)</code>.
   * 
   * @param name
   *          the name of the form item
   * @return the value of the item with the name given in parameter
   */
  public FormComplexValue getFormComplexValue(String name)
  {
    return formComplexValues.get(name);
  }



  /**
   * convenient method that adds a new {@link FormComplexValue}. It is
   * equivalent to
   * <code>getFormValues.put(formComplexValue.getName(), formComplexValue)</code>.
   * 
   * @param formComplexValue
   *          the form value to add
   */
  public void addFormComplexValue(FormComplexValue formComplexValue)
  {
    formComplexValues.put(formComplexValue.getName(), formComplexValue);
  }



  /**
   * returns all the values of the form items of the form associated with this
   * object indexed by their names.
   * 
   * @return the map of all the values of the form items of the form associated
   *         with this object indexed by their names
   */
  public Map<String, FormComplexValue> getFormComplexValues()
  {
    return formComplexValues;
  }



  /**
   * getter for the formSimpleValues property.
   * 
   * @return the formSimpleValues
   */
  public Map<String, FormSimpleValue> getFormSimpleValues()
  {
    return formSimpleValues;
  }



  /**
   * setter for the formSimpleValues property.
   * 
   * @param formSimpleValues
   *          the formSimpleValues to set
   */
  public void setFormSimpleValues(Map<String, FormSimpleValue> formSimpleValues)
  {
    this.formSimpleValues = formSimpleValues;
  }

}
